<template>
	<!-- 金刚区 -->
	<view v-show="!isSortType && menus.length" :class="bgStyle?'borderRadius15':''" :style="{background:bgColor,margin:'0 '+prConfig*2+'rpx',marginTop:mbConfig*2+'rpx'}">
		<view v-if="isMany">
			<view class="swiper">
				<swiper :interval="interval" :duration="duration" :style="'height:'+(navHigh+13)+'px;'" @change='bannerfun'>
					<block>
						<swiper-item v-for="(item,indexw) in menuList" :key="indexw">
							<view class="nav acea-row" :id="'nav' + indexw">
								<view :style="'color:' + titleColor" class="item" :class="number===1?'four':number===2?'five':''" v-for="(itemn,indexn) in item.list" :key="indexn" @click="menusTap(itemn.info[1].value)">
									<view class="pictrue skeleton-radius" :class="menuStyle?'':'on'">
										<image :src="itemn.img" mode="aspectFill"></image>
									</view>
									<view class="menu-txt">{{ itemn.info[0].value }}</view>
								</view>
							</view>
						</swiper-item>
					</block> 
				</swiper>
			</view>
			<view class="dot acea-row row-center-wrapper" v-if="docConfig<2 && menuList.length>1">
				<view class="dot-item" :class="{ 'line_dot-item': docConfig === 0,'': docConfig === 1}" :style="active==index?'background:'+ dotColor:''" v-for="(item,index) in menuList"></view>
			</view>
			<!-- <view class="list_banner"> 多模块构建
				<image @click="imgToUrl(parmsUrl.left1)" class="image1" :src="parmsUrl.left1.img_url" mode=""></image>
				<view class="view_image">
					<image @click="imgToUrl(parmsUrl.right11)" :src="parmsUrl.right11.img_url" mode=""></image>
					<image @click="imgToUrl(parmsUrl.right12)" :src="parmsUrl.right12.img_url" mode=""></image>
				</view>
			</view> -->
			<!-- <view style="width: 100%;background-color: #fff;">
				<view class="kefu_box">
					<view class="kefu_box_view">
						<image src="https://aolaic.shangyunji.com/uploads/store/kefu.png" mode=""></image>
						<view>
							<h3>官方微信客服</h3>
							<p>买遍全球美妆，顺丰发货</p>
						</view>
					</view>
					<view class="kefu1_box">
						<image src="https://aolaic.shangyunji.com/uploads/store/lianxi.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="footer">
				<image src="https://aolaic.shangyunji.com/uploads/store/yinliang.png" mode=""></image>
				<p>公告：全场9.5折优惠~</p>
			</view>
			<view style="width: 100%;background-color: #fff;">
				<view class="kefu_box">
					<view class="kefu_box_view">
						<image style="width: 80rpx; height: 68rpx;" src="https://aolaic.shangyunji.com/uploads/store/guan.png" mode=""></image>
						<view>
							<h3>品牌街</h3>
							<p>特价让你尖叫不停</p>
						</view>
					</view>
					<view class="kefu1_box">
						<image style="width: 130rpx;height: 25rpx;" src="https://aolaic.shangyunji.com/uploads/store/right_text1.png" mode=""></image>
					</view>
				</view>
			</view> -->
			
		</view>
		<view class="nav oneNav" v-else>
			<scroll-view scroll-x="true" style="white-space: nowrap; display: flex" show-scrollbar="false">
				<block v-for="(item, index) in menus" :key="index">
					<view class="item" :style="'color:' + titleColor" @click="menusTap(item.info[1].value)">
						<view class="pictrue skeleton-radius" :class="menuStyle?'':'on'">
							<image :src="item.img" mode="aspectFill"></image>
						</view>
						<view class="menu-txt">{{ item.info[0].value }}</view>
					</view>
				</block>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getDiyNew
	} from '@/api/api.js';
	export default {
		name: 'menus',
		props: {
			dataConfig: {
				type: Object,
				default: () => {}
			},
			isSortType: {
				type: String | Number,
				default: 0
			}
		},
		data() {
			return {
				interval: 3000,
				duration: 500,
				menus: this.dataConfig.menuConfig.list || [],
				titleColor: this.dataConfig.titleColor.color[0].item,
				mbConfig: this.dataConfig.mbConfig.val,
				rowsNum: this.dataConfig.rowsNum.type,
				number: this.dataConfig.number.type,
				isMany: this.dataConfig.tabConfig.tabVal,
				menuStyle: this.dataConfig.menuStyle.type,
				docConfig: this.dataConfig.pointerStyle.type,
				dotColor: this.dataConfig.pointerColor.color[0].item,
				bgColor: this.dataConfig.bgColor.color[0].item,
				bgStyle: this.dataConfig.bgStyle.type,
				prConfig: this.dataConfig.prConfig.val,
				navHigh: 170,
				menuList: [],
				active: 0,
				parmsUrl:{}
			};
		},
		created() {
		},
		mounted() {
			if (this.rowsNum === 0) {
				if (this.number === 0) {
					this.pageNum(6)
				} else if (this.number === 1) {
					this.pageNum(8)
				} else {
					this.pageNum(10)
				}
			} else if (this.rowsNum === 1) {
				if (this.number === 0) {
					this.pageNum(9)
				} else if (this.number === 1) {
					this.pageNum(12)
				} else {
					this.pageNum(15)
				}
			} else {
				if (this.number === 0) {
					this.pageNum(12)
				} else if (this.number === 1) {
					this.pageNum(16)
				} else {
					this.pageNum(20)
				}
			}
			this.$nextTick(() => {
				if (this.menuList.length&&this.isMany) {
					let that = this
					// #ifdef H5
					that.menuHeight()
					// #endif
					// #ifndef H5
					setTimeout(() => {
						that.menuHeight()
					},150)
					// #endif
				}
			})
			this.tabListData()
		},
		methods: {
			bannerfun(e) {
				this.active = e.detail.current;
			},
			menuHeight(){
				let that = this;
				const query = uni.createSelectorQuery().in(this);
				query.select('#nav0').boundingClientRect(data => {
					that.navHigh = data.height;
				}).exec();
			},
			pageNum(num) {
				let count = Math.ceil(this.menus.length / num);
				let goodArray = new Array();
				for (let i = 0; i < count; i++) {
					let list = this.menus.slice(i * num, i * num + num);
					if (list.length)
						goodArray.push({
							list: list
						});
				}
				this.$set(this, 'menuList', goodArray);
			},
			menusTap(url) {
				this.$util.JumpPath(url);
			},
			tabListData(){
				getDiyNew({}).then((res)=>{
					this.parmsUrl.left1 = res.data.left1
					this.parmsUrl.right11 = res.data.right11
					this.parmsUrl.right12 = res.data.right12
				})
			},
			imgToUrl(pathType){
				console.log('pathType.link',pathType.link)
				uni.navigateTo({
					url:`/${pathType.link}`
				})
			}
		}
	};
</script>

<style lang="scss">
	.list_banner{
		width: 95%;
		margin: auto;
		display: flex;
		padding-bottom: 20rpx;
		justify-content: space-between;
		.image1{
			width: 348rpx;
			height: 348rpx;
		}
		.view_image{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			image{
				width: 348rpx;
				height: 167rpx;
			}
		}
	}
	.footer{
		width: 100%;
		padding: 20rpx;
		display: flex;
		background-color: #222222;
		flex-direction: row;
		image{
			width: 33rpx;
			height: 32rpx;
		}
		p{
			margin-left: 20rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}
	}
	.kefu_box{
		padding: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.kefu_box_view{
			display: flex;
			align-items: center;
			image{
				width: 120rpx;
				height: 126rpx;
				margin-right: 20rpx;
			}
			h3{
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #222222;
			}
			span{
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #222222;
			}
			
		}
		.kefu1_box{
			image{
				width: 120rpx;
				height: 48rpx;
			}
		}
	}
	.dot {
		width: 100%;
		padding-bottom: 20rpx;
	
		.instruct {
			width: 50rpx;
			height: 36rpx;
			line-height: 36rpx;
			background-color: rgba(0, 0, 0, 0.8);
			color: #fff;
			border-radius: 16rpx;
			font-size: 24rpx;
			text-align: center;
		}
	
		.dot-item {
			width: 10rpx;
			height: 10rpx;
			background: rgba(0, 0, 0, .4);
			border-radius: 50%;
			margin: 0 4px;
	
			&.line_dot-item {
				width: 20rpx;
				height: 5rpx;
				border-radius: 3rpx;
			}
		}
	}
	.nav {
		&.oneNav{
			padding-bottom: 25rpx;
		}
		.item {
			margin-top: 30rpx;
			width: 150rpx;
			text-align: center;
			font-size: 24rpx;
			display: inline-block;

			.pictrue {
				width: 90rpx;
				height: 90rpx;
				margin: 0 auto;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}

				&.on {
					image {
						border-radius: 0;
					}
				}
			}

			.menu-txt {
				margin-top: 15rpx;
			}
		}
	}

	.swiper {
		z-index: 20;
		position: relative;
		overflow: hidden;
		.nav {
			.item {
				width: 33.3333%;

				&.four {
					width: 25%;
				}

				&.five {
					width: 20%;
				}
			}
		}

		swiper,
		.swiper-item {
			width: 100%;
			display: block;
		}
	}
</style>
